package cn.edu.cqvie.jdk8.fun;

import java.util.Optional;

public class OptionalTest {

    public static void main(String[] args) {
        Optional<String> optional = Optional.ofNullable("hello");
        optional.ifPresent(item -> System.out.println(item));

        System.out.println("-------------");
        System.out.println(optional.orElse("world"));

        System.out.println("-------------");
        //为空通过 Supplier 来返回值
        System.out.println(optional.orElseGet(() -> "nihao"));
    }
}
